package com.zm.tools.util.core.generatecode.common;

import com.zm.tools.util.core.TableMetadateReadUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * @author zoum
 * @create 2018/9/6 10:57
 */
public class GenerateCodeUtil {

    private TableMetadateReadUtil tableMetadateReadUtil = new TableMetadateReadUtil();

    private String baseFilePath = "E:\\git\\data";

    public void generateCode(String companyName, String appName, String ... tableNames) throws IOException{
        Arrays.stream(tableNames).forEach(tableName -> {
            StringBuilder newTableName = new StringBuilder();
            Arrays.stream(tableName.split("_")).forEach(s -> {
                newTableName.append(StringUtils.isBlank(s) ? "" : StringUtils.capitalize(s));
            });
            try {
                GenerateModelCode.generate(baseFilePath, newTableName.toString(), companyName, appName);
                GenerateFacadeCode.generate(baseFilePath, newTableName.toString(), companyName, appName);
                GenerateManagerCode.generate(baseFilePath, newTableName.toString(), companyName,appName);
            }catch (IOException e){
                e.printStackTrace();
            }
        });
    }

    public TableMetadateReadUtil getTableMetadateReadUtil() {
        return tableMetadateReadUtil;
    }

    public void setTableMetadateReadUtil(TableMetadateReadUtil tableMetadateReadUtil) {
        this.tableMetadateReadUtil = tableMetadateReadUtil;
    }
}
